package com.qikecn.utils;

import com.jfinal.plugin.activerecord.Table;
import com.jfinal.plugin.activerecord.TableMapping;

public class GenTableBeanAutoUtil {

	public static String genTableBean(String className){
		try {
			Class modelClass = Class.forName(className);
			Table table = TableMapping.me().getTable(modelClass);
			String rows = "";
			for(String key : table.getColumnTypeMap().keySet()){
				System.out.println("key="+key);
				System.out.println("name="+table.getColumnTypeMap().get(key).getName());
				rows += "@Expose" + "\n";
				rows += "private "+table.getColumnTypeMap().get(key).getName() + " " + key + ";\n";
			}
			rows = rows.replaceAll("java.sql.Timestamp", "java.lang.String");
			rows = rows.replaceAll("java.lang.", "");
			return rows;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return "";		
	}
	
	public static void main(String[] args) {
		GenTableBeanAutoUtil.genTableBean("com.qikecn.api.model.Ad");
	}
}
